package com.runen.infinitemovement.treenode;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.runen.infinitemovement.R;
import com.runen.infinitemovement.adapter.treeview.TreeNode;
import com.runen.infinitemovement.adapter.treeview.TreeViewBinder;
import com.runen.rxnetlibrary.utils.LogUtil;


/**
 * BranchViewBinder
 *
 * @author 林zero
 * @date 2018/1/17
 */

public class BranchViewBinder extends TreeViewBinder<BranchViewBinder.ViewHolder> {

    @Override
    public int getLayoutId() {
        return R.layout.item_branch;
    }

    @Override
    public int getToggleId() {
        return R.id.llParent;
    }

    @Override
    public int getCheckedId() {
        return R.id.ivCheck;
    }

    @Override
    public int getClickId() {
        return R.id.tvName;
    }

    @Override
    public ViewHolder creatViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public void bindViewHolder(ViewHolder holder, int position, TreeNode treeNode) {
        BranchNode branchNode = (BranchNode) treeNode.getValue();
        ImageView ivCheck = ((ImageView) holder.findViewById(R.id.ivCheck));
        RelativeLayout llParent = ((RelativeLayout) holder.findViewById(R.id.rl_content_info));
        LinearLayout ll_add = ((LinearLayout) holder.findViewById(R.id.ll_add));
        View v_line = (View) holder.findViewById(R.id.v_line);
        if (((BranchNode) treeNode.getValue()).getName().equals("添加")) {
            ll_add.setVisibility(View.VISIBLE);
            llParent.setVisibility(View.GONE);
            v_line.setVisibility(View.GONE);
        } else {
            ll_add.setVisibility(View.GONE);
            llParent.setVisibility(View.VISIBLE);
            v_line.setVisibility(View.VISIBLE);
            ((TextView) holder.findViewById(R.id.tvName)).setText(((BranchNode) treeNode.getValue()).getName());
        }
        if (treeNode.getChildNodes().size() == 0) {
            holder.findViewById(R.id.ivNode).setVisibility(View.GONE);
        } else {
            holder.findViewById(R.id.ivNode).setRotation(treeNode.isExpanded() ? 90 : 0);
            holder.findViewById(R.id.ivNode).setVisibility(View.VISIBLE);
        }
//        if (branchNode.getPoint() == holder.getAdapterPosition()) {
//            ivCheck.setImageResource(R.mipmap.ico_selected_circle_red);
//            LogUtil.e("branchNode", "1");
//        } else {
//            ivCheck.setImageResource(R.mipmap.ico_select_circle_normal);
//            LogUtil.e("branchNode", "0");
//        }
    }

    class ViewHolder extends TreeViewBinder.ViewHolder {
        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
